import QtQuick 2.0
import QtQuick.Layouts 1.14
import QtQuick.Extras 1.4
import Qt.labs.platform 1.1
import QtQuick.Controls 2.14
import QtQuick 2.14
import "./components"

Item {
    id:root
    anchors.fill: parent

    function showPage( index)
    {
        page_home.visible     = (index === 0)
        page_openfile.visible = (index === 1)
        // page_wifi.visible     = (curTapIndex === 1)
        page_settings.visible = (index === 2)
    }

    RowLayout{
        spacing: 0
        anchors.fill: parent
        //tab
        ExTapPageControl{
            id:tab_menu
            anchors.topMargin: 40
            anchors.leftMargin: 40
            onCurTapIndexChanged: {
                console.log(curTapIndex)
                showPage(curTapIndex)
            }
        }

        Rectangle{
            id:page_home
            Layout.fillHeight: true
            Layout.fillWidth: true
            color: "transparent"
            visible: true

            RowLayout{
                anchors.fill: parent
                Rectangle{
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    color: "transparent"
                    Image {
                        width: 390
                        height: 485
                        source: "qrc:/img/LOGO.svg"
                        anchors.centerIn: parent
                        anchors.horizontalCenterOffset: 10
                        anchors.verticalCenterOffset: 10
                    }
                }

                Rectangle{
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    Layout.topMargin: 30
                    Layout.bottomMargin: 30
                    color: "transparent"

                    ColumnLayout{
                        anchors.fill: parent
                        spacing: 10

                        ExMotroControl1{
                            Layout.alignment: Qt.AlignHCenter
                        }

                        ExOperatesControl{
                            Layout.alignment: Qt.AlignHCenter
                        }
                    }
                }
            }
        }

        Rectangle{
            id:page_openfile
            Layout.fillHeight: true
            Layout.fillWidth: true
            visible: false
            color: "transparent"
            RowLayout{
                anchors.fill: parent
                ExOpenFileControl{
                    Layout.alignment: Qt.AlignHCenter
                    onWifiClicked: {
                        // paege_printfileSettings.visible=true
                        tab_menu.enabled=false
                        page_wifi.visible=true
                    }

                    onUsbClicked: {
                        page_file.visible=true
                        tab_menu.enabled=false
                        // showPage(-1)
                    }

                }
            }
        }

        Rectangle{
            id:page_settings
            Layout.fillHeight: true
            Layout.fillWidth: true
            color: "transparent"
            visible: false
        }

    }

    Rectangle{
        id:page_wifi
        anchors.fill: parent
        color: "transparent"
        visible: false
        RowLayout{
            anchors.fill: parent
            ExWiFiControl{
                Layout.alignment: Qt.AlignHCenter
                onQuit: {
                    page_wifi.visible = false
                    tab_menu.enabled=true
                    page_file.visible=true
                    // showPage(-1)
                }
                onRefresh: {
                    console.log("refresh ")
                }
            }
        }
    }
    Rectangle{
        id:page_file
        anchors.fill: parent
        color: "transparent"
        visible: false
        RowLayout{
            anchors.fill: parent
            ExFilePage{
                Layout.alignment: Qt.AlignHCenter

                onQuitClicked: {
                    page_file.visible = false
                    tab_menu.enabled=true
                    page_wifi.visible = false
                }
                onPrintAddClicked:{
                   paege_printfileSettings.visible=true
                }
            }
        }
    }
    Rectangle{
        id:paege_printfileSettings
        anchors.fill: parent
        color: "transparent"
        visible: false
        RowLayout{
            anchors.fill: parent
            ExPrintFileSettings{
                onQuitClicked:{
                    paege_printfileSettings.visible=false
                    tab_menu.enabled=true
                }
            }
        }
    }
}
